//
//  HOPDismissAnimation.swift
//  WB01
//
//  Created by HOP on 16/1/3.
//  Copyright © 2016年 HOP. All rights reserved.
//

import UIKit
/// 控制关闭时的动画
class HOPDismissAnimation: NSObject,UIViewControllerAnimatedTransitioning {
// 转场时间
    func transitionDuration(transitionContext: UIViewControllerContextTransitioning?) -> NSTimeInterval {
        return 0.25
    }
      // 实现动画
    func animateTransition(transitionContext: UIViewControllerContextTransitioning) {
         // 1. 获取到modal出来的控制器的view
        let fromView = transitionContext.viewForKey(UITransitionContextFromViewKey)
        // 2. 做动画
        UIView.animateWithDuration(transitionDuration(transitionContext), animations: { () -> Void in
            // 注意: s缩放的Y值不能写0,如果填0就没有动画效果了
            fromView?.transform = CGAffineTransformMakeScale(1, 0.0001)
            }) { (_) -> Void in
                // 告诉系统关闭的转场动画完成了
                transitionContext.completeTransition(true)
        }
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}
